﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using sysWeb = System.Web.Caching;
using System.Collections;

namespace WebCache
{
    public class GlobalCache:BaseCache
    {

        private static sysWeb.Cache cache = HttpContext.Current.Cache;
        private static object syncLocker = new object();

        public override string[] Keys
        {
            get 
            {
                IDictionaryEnumerator enumerator = cache.GetEnumerator();
                ArrayList list = new ArrayList();
                while (enumerator.MoveNext()) list.Add(enumerator.Key.ToString());
                return (string[])list.ToArray();
            }
        }

        public override object this[string key]
        {
            get
            {
                return cache[key];
            }
            set
            {
                lock (syncLocker)
                {
                    cache[key] = value;
                }
            }
        }

        public override void Remove(string key)
        {
            cache.Remove(key);
        }
    }
}
